﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:FIN_EXCLOANIN
	/// </summary>
	public partial class FIN_EXCLOANIN : BaseDAL<GSLMS.Entity.TB_FIN_EXCLOANIN>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public FIN_EXCLOANIN()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_FIN_EXCLOANIN model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_CUSTID", model.CUSTID),
								new OracleParameter("P_PAYMENT", model.PAYMENT),
								new OracleParameter("P_AMT", model.AMT),
								new OracleParameter("P_LEFTAMT", model.LEFTAMT),
								new OracleParameter("P_STARTDATE", model.STARTDATE),
								new OracleParameter("P_ACCOUNTNAME", model.ACCOUNTNAME),
								new OracleParameter("P_ACCOUNTID", model.ACCOUNTID),
								new OracleParameter("P_RATE", model.RATE),
								new OracleParameter("P_ENDDATE", model.ENDDATE),
								new OracleParameter("P_EXCHANGENO", model.EXCHANGENO),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_TOUSER", model.TOUSER),
								new OracleParameter("P_CREATEBY", model.CREATEBY),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_CLEARSTATUS", model.CLEARSTATUS),
								new OracleParameter("P_CLEARBY", model.CLEARBY),
								new OracleParameter("P_CLEARDATE", model.CLEARDATE),
								new OracleParameter("P_SPAREFIELD1", model.SPAREFIELD1),
								new OracleParameter("P_SPAREFIELD2", model.SPAREFIELD2),
								new OracleParameter("P_SPAREFIELD3", model.SPAREFIELD3)};
  
			for (int i = 0; i < 22; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_fin_excloanin_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_FIN_EXCLOANIN model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_CUSTID", model.CUSTID),
								new OracleParameter("P_PAYMENT", model.PAYMENT),
								new OracleParameter("P_AMT", model.AMT),
								new OracleParameter("P_LEFTAMT", model.LEFTAMT),
								new OracleParameter("P_STARTDATE", model.STARTDATE),
								new OracleParameter("P_ACCOUNTNAME", model.ACCOUNTNAME),
								new OracleParameter("P_ACCOUNTID", model.ACCOUNTID),
								new OracleParameter("P_RATE", model.RATE),
								new OracleParameter("P_ENDDATE", model.ENDDATE),
								new OracleParameter("P_EXCHANGENO", model.EXCHANGENO),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_TOUSER", model.TOUSER),
								new OracleParameter("P_CREATEBY", model.CREATEBY),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_CLEARSTATUS", model.CLEARSTATUS),
								new OracleParameter("P_CLEARBY", model.CLEARBY),
								new OracleParameter("P_CLEARDATE", model.CLEARDATE),
								new OracleParameter("P_SPAREFIELD1", model.SPAREFIELD1),
								new OracleParameter("P_SPAREFIELD2", model.SPAREFIELD2),
								new OracleParameter("P_SPAREFIELD3", model.SPAREFIELD3)};
  
			for (int i = 0; i < 22; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_fin_excloanin_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_fin_excloanin_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_FIN_EXCLOANIN DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_FIN_EXCLOANIN model = new GSLMS.Entity.TB_FIN_EXCLOANIN();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["CUSTID"]!=null && dr["CUSTID"].ToString()!="")
				{
					model.CUSTID=OracleHelper.ToLong(dr["CUSTID"].ToString());
				}
				if(dr["PAYMENT"]!=null && dr["PAYMENT"].ToString()!="")
				{
                    model.PAYMENT = OracleHelper.ToInt(dr["PAYMENT"].ToString());
				}
				if(dr["AMT"]!=null && dr["AMT"].ToString()!="")
				{
					model.AMT=OracleHelper.ToDecimal(dr["AMT"].ToString());
				}
				if(dr["LEFTAMT"]!=null && dr["LEFTAMT"].ToString()!="")
				{
					model.LEFTAMT=OracleHelper.ToDecimal(dr["LEFTAMT"].ToString());
				}
				if(dr["STARTDATE"]!=null && dr["STARTDATE"].ToString()!="")
				{
					model.STARTDATE=DateTime.Parse(dr["STARTDATE"].ToString());
				}
				if(dr["ACCOUNTNAME"]!=null && dr["ACCOUNTNAME"].ToString()!="")
				{
					model.ACCOUNTNAME=dr["ACCOUNTNAME"].ToString();
				}
				if(dr["ACCOUNTID"]!=null && dr["ACCOUNTID"].ToString()!="")
				{
					model.ACCOUNTID=OracleHelper.ToLong(dr["ACCOUNTID"].ToString());
				}
				if(dr["RATE"]!=null && dr["RATE"].ToString()!="")
				{
					model.RATE=OracleHelper.ToDecimal(dr["RATE"].ToString());
				}
				if(dr["ENDDATE"]!=null && dr["ENDDATE"].ToString()!="")
				{
					model.ENDDATE=DateTime.Parse(dr["ENDDATE"].ToString());
				}
				if(dr["EXCHANGENO"]!=null && dr["EXCHANGENO"].ToString()!="")
				{
					model.EXCHANGENO=dr["EXCHANGENO"].ToString();
				}
				if(dr["REMARK"]!=null && dr["REMARK"].ToString()!="")
				{
					model.REMARK=dr["REMARK"].ToString();
				}
				if(dr["TOUSER"]!=null && dr["TOUSER"].ToString()!="")
				{
					model.TOUSER=dr["TOUSER"].ToString();
				}
				if(dr["CREATEBY"]!=null && dr["CREATEBY"].ToString()!="")
				{
					model.CREATEBY=dr["CREATEBY"].ToString();
				}
				if(dr["CREATEDATE"]!=null && dr["CREATEDATE"].ToString()!="")
				{
					model.CREATEDATE=DateTime.Parse(dr["CREATEDATE"].ToString());
				}
				if(dr["STATUS"]!=null && dr["STATUS"].ToString()!="")
				{
                    model.STATUS = OracleHelper.ToInt(dr["STATUS"].ToString());
				}
				if(dr["CLEARSTATUS"]!=null && dr["CLEARSTATUS"].ToString()!="")
				{
                    model.CLEARSTATUS = OracleHelper.ToInt(dr["CLEARSTATUS"].ToString());
				}
				if(dr["CLEARBY"]!=null && dr["CLEARBY"].ToString()!="")
				{
					model.CLEARBY=dr["CLEARBY"].ToString();
				}
				if(dr["CLEARDATE"]!=null && dr["CLEARDATE"].ToString()!="")
				{
					model.CLEARDATE=DateTime.Parse(dr["CLEARDATE"].ToString());
				}
				if(dr["SPAREFIELD1"]!=null && dr["SPAREFIELD1"].ToString()!="")
				{
                    model.SPAREFIELD1 = OracleHelper.ToInt(dr["SPAREFIELD1"].ToString());
				}
				if(dr["SPAREFIELD2"]!=null && dr["SPAREFIELD2"].ToString()!="")
				{
					model.SPAREFIELD2=dr["SPAREFIELD2"].ToString();
				}
				if(dr["SPAREFIELD3"]!=null && dr["SPAREFIELD3"].ToString()!="")
				{
					model.SPAREFIELD3=dr["SPAREFIELD3"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_FIN_EXCLOANIN GetByID(long ID)
		{
			GSLMS.Entity.TB_FIN_EXCLOANIN sModel = new GSLMS.Entity.TB_FIN_EXCLOANIN();
			string sql = "";
			sql = "select * from TB_FIN_EXCLOANIN where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_FIN_EXCLOANIN> GetList(GSLMS.Entity.TB_FIN_EXCLOANIN searchParam)
		{
			var list=new List<GSLMS.Entity.TB_FIN_EXCLOANIN>();
			DataTable dt = null;
			string tblName = "TB_FIN_EXCLOANIN";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_FIN_EXCLOANIN model = new GSLMS.Entity.TB_FIN_EXCLOANIN();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

